package schoolWork.work05.Example1;
//导入图形用户界面相关的类

import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;

//窗口从 JFrame 继承而来
public class MyFrm_Hybrid extends JFrame {
    //声明界面所需要的控件
    JButton[] btn = new JButton[4];
    String[] str = {"OK", "cancel", "Last", "Next"};
    JLabel lbl_Name = new JLabel("Name");
    JLabel lbl_Number = new JLabel("Number");
    JLabel lbl_Score = new JLabel("score");

    JTextField txt_Name = new JTextField();
    JTextField txt_No = new JTextField();
    JTextField txt_Score = new JTextField();

    //在构造方法中将控件放入 JFrame 中
    public MyFrm_Hybrid() {
        for (int i = 0; i < 4; i++) {
            btn[i] = new JButton(str[i]);
        }
        //上部分使用 GridLayout 布局
        JPanel jp1 = new JPanel();
        Border titleBorder1 = BorderFactory.createTitledBorder("Infomation");
        jp1.setBorder(titleBorder1);
        jp1.setLayout(new GridLayout(3, 2));
        jp1.add(lbl_Name);
        jp1.add(txt_Name);
        jp1.add(lbl_Number);
        jp1.add(txt_No);
        jp1.add(lbl_Score);
        jp1.add(txt_Score);
        //下部分使用 FlowLayout布局
        JPanel jp2 = new JPanel();
        jp2.add(btn[0]);
        jp2.add(btn[1]);
        jp2.add(btn[2]);
        jp2.add(btn[3]);
        //加 jp1,jp2 加入到窗口中
        add(jp1, BorderLayout.CENTER);
        add(jp2, BorderLayout.SOUTH);
        setSize(300, 200);
        setLocationRelativeTo(null);
        setVisible(true);
        setTitle("Mixed Layout");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}